<!--报名项目-->
<template>
  <div>
    <div style="display: flex; max-height: 20px; margin-left: -20px">
      <h5 style="margin-left: 30px">项目编号</h5>
      <el-input style="margin-top: -5px; width:120px; margin-left: 10px" placeholder="请输入项目编号" v-model="projectNumber"></el-input>
      <h5 style="margin-left: 30px">项目名称</h5>
      <el-input style="margin-top: -5px; width:120px; margin-left: 10px" placeholder="请输入项目名称" v-model="projectName" ></el-input>
      <el-button type="primary" style="margin-top: -5px; margin-left: 30px" icon="el-icon-search" @click="init">查询</el-button>
      <el-button type="warning" style="margin-top: -5px; margin-left: 10px" icon="el-icon-refresh" @click="reset">重置</el-button>
    </div>
    <div style="display: flex;">
      <el-table :data="tableData" style="margin-top: 10px" height="500">
        <el-table-column fixed label="序号"  width="45">
          <template slot-scope="scope">
            {{ scope.$index + 1 }}
          </template>
        </el-table-column>
        <el-table-column prop="announcementName" label="公告名称" width="250"></el-table-column>
        <el-table-column prop="projectNumber" label="项目编号" width="100"></el-table-column>
        <el-table-column prop="projectName" label="项目名称" width="140"></el-table-column>
        <el-table-column prop="quantity" label="数量" width="45"></el-table-column>
        <el-table-column prop="budget" label="预算（万元）" width="100"></el-table-column>
        <el-table-column prop="projectType" label="项目类型" width="80"></el-table-column>
        <el-table-column prop="meetingRoom" label="会议室" width="100"></el-table-column>
        <el-table-column prop="announDate" label="公告时间" width="170"></el-table-column>
        <el-table-column prop="tenderOfficer" label="招标负责人" width="90"></el-table-column>
        <el-table-column label="操作" width="150">
          <template slot-scope="scope">
            <el-button type="success" @click="handleLook(scope.row)">查看</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div style="padding: 10px 0;margin-left: 800px">
      <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="pageNum"
          :page-sizes="[10, 15, 20,30]"
          :page-size="pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total">
      </el-pagination>
    </div>
    <el-dialog :visible.sync="dialogLookVisible"
               style="text-align: center;"
               width="1000"
    >
      <div class="dialog-title" style="margin-top: -40px">{{ lookForm.dialogTitle }}</div>
      <el-descriptions title="" style="display: inline-block;" column="4" size="small" border>
        <el-descriptions-item label="项目预算（万元）">{{lookForm.budget}}</el-descriptions-item>
        <el-descriptions-item label="采购人">{{ lookForm.applyingDepartment }}</el-descriptions-item>
        <el-descriptions-item label="开标时间" :contentStyle="{'text-align': 'right'}">{{ lookForm.meetTime }}</el-descriptions-item>
        <el-descriptions-item label="进度">
          <span v-if="lookForm.status === 1">待公告</span>
          <span v-else-if="lookForm.status === 2">已公告</span>
          <span v-else-if="lookForm.status === 3">待公示</span>
          <span v-else-if="lookForm.status === 4">已公示</span>
          <span v-else-if="lookForm.status === 5">已完成</span>
        </el-descriptions-item>
      </el-descriptions>
      <el-card>
        <el-descriptions title="" style="" column="2" size="mini">
          <el-descriptions-item label="投标单位签到时间">{{ lookForm.meetTime }}</el-descriptions-item>
          <el-descriptions-item label="资质审核时间">{{ lookForm.meetTime }}</el-descriptions-item>
          <el-descriptions-item label="开标时间">{{ lookForm.meetTime }}</el-descriptions-item>
          <el-descriptions-item label="开标地点">{{ lookForm.meetLoca }}</el-descriptions-item>
          <el-descriptions-item label="公告内容">{{lookForm.announcementText}}</el-descriptions-item>
        </el-descriptions>
      </el-card>
    </el-dialog>
  </div>
</template>

<script>
import {getProjectPageByStatusSpace} from "@/api/project";
import {getAnnouncementsByProjectNumbers, getEnlistAnnouncementsBydepartment} from "@/api/announcement";
import {getMeetByProjectName} from "@/api/meet";

export default {
  data() {
    return {
      user: localStorage.getItem('user') ? JSON.parse(localStorage.getItem('user')) : {},
      tableData: [],
      pageNum: 1, //当前页
      pageSize: 10, //每页显示条数
      total: 0, //总条数
      projectNumber: "", //项目编号
      projectName: "", //项目名称
      dialogLookVisible: false,
      lookForm: {},
    };
  },
  created() {
    this.init();
  },
  methods: {
    init() {
      getEnlistAnnouncementsBydepartment(this.pageNum, this.pageSize,this.user.department,this.projectName,this.projectNumber).then(res => {
        this.tableData = res.records
        this.tableData.forEach(t => {
          t.announDate = t.announcementStartTime + " - " + t.announcementEndTime
        })
        this.total = res.total
      })
    },
    async handleLook(row) { //查看
      this.lookForm = row
      this.lookForm.dialogTitle = `${row.projectName}(招标项目编号：${row.projectNumber})`
      await getMeetByProjectName(row.projectName).then(res => {
        console.log(res)
        this.lookForm.meetTime = res ? this.formatTime(res.meetTime) : "暂无";
        this.lookForm.meetLoca = res ? res.meetLoca : "暂无";
        this.dialogLookVisible = true
      })
      this.dialogLookVisible = true

    },
    formatTime(meetTime) { // 格式化时间
      const date = new Date(meetTime);

      const year = date.getFullYear();
      const month = date.getMonth() + 1; // 月份从0开始，所以要加1
      const day = date.getDate();
      const hour = date.getHours();
      const minute = date.getMinutes();

      // 判断是上午还是下午
      const ampm = hour >= 12 ? '下午' : '上午';
      const hour12 = hour % 12 === 0 ? 12 : hour % 12; // 12小时制
      const formattedMinute = minute < 10 ? '0' + minute : minute; // 补充分钟前导零

      return `${year}年${month}月${day}日${ampm}${hour12}:${formattedMinute}`;
    },
    handleSizeChange(val) {
      this.pageSize = val;
      this.init();
    },
    handleCurrentChange(val) {
      this.pageNum = val;
      this.init();
    },
    reset() {
      this.projectName = "";
      this.projectNumber = "";
      this.init();
    },
  }
};
</script>

<style scoped>

</style>
